package hos.core.result;

import java.io.Serializable;

/**
 * <p>Title: ResultData </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2024-06-27 15:08
 */
public class ResultData<DATA> implements Serializable {
    private final Integer code;
    private final String message;

    private final DATA data;

    public static ResultData<?> success() {
        return new ResultData<>(ResultCode.SUCCESS, null);
    }

    public static <DATA> ResultData<DATA> success(DATA data) {
        return new ResultData<DATA>(ResultCode.SUCCESS, data);
    }

    public static ResultData<?> empty() {
        return new ResultData<>(ResultCode.EMPTY);
    }

    public static ResultData<?> network() {
        return new ResultData<>(ResultCode.NETWORK);
    }

    public static ResultData<?> failure() {
        return new ResultData<>(ResultCode.FAILURE);
    }

    public static ResultData<?> failure(ResultCode code) {
        return new ResultData<>(code);
    }

    public static <DATA> ResultData<DATA> failure(ResultCode code, DATA data) {
        return new ResultData<DATA>(code, data);
    }

    private ResultData(ResultCode code) {
        this(code, null);
    }

    private ResultData(ResultCode code, DATA data) {
        this.code = code.getCode();
        this.message = code.getMessage();
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public DATA getData() {
        return data;
    }
}
